Expand description
pulp
is a safe abstraction over SIMD instructions, that allows you to write a function once
and dispatch to equivalent vectorized versions based on the features detected at runtime.
§Autovectorization example
use pulp::Arch;
let mut v = (0..1000).map(|i| i as f64).collect::<Vec<_>>();
let arch = Arch::new();
arch.dispatch(|| {
for x in &mut v {
*x *= 2.0;
}
});
for (i, x) in v.into_iter().enumerate() {
assert_eq!(x, 2.0 * i as f64);
}
§Manual vectorization example
use pulp::{Arch, Simd, WithSimd};
struct TimesThree<'a>(&'a mut [f64]);
impl<'a> WithSimd for TimesThree<'a> {
type Output = ();
#[inline(always)]
fn with_simd<S: Simd>(self, simd: S) -> Self::Output {
let v = self.0;
let (head, tail) = S::f64s_as_mut_simd(v);
let three = simd.f64s_splat(3.0);
for x in head {
*x = simd.f64s_mul(three, *x);
}
for x in tail {
*x = *x * 3.0;
}
}
}
let mut v = (0..1000).map(|i| i as f64).collect::<Vec<_>>();
let arch = Arch::new();
arch.dispatch(TimesThree(&mut v));
for (i, x) in v.into_iter().enumerate() {
assert_eq!(x, 3.0 * i as f64);
}
Modules§
- x86
x86 or x86-64 Low level x86 API.
Macros§
Structs§
- Bitmask type for 8 elements, used for mask operations on AVX512.
- Bitmask type for 16 elements, used for mask operations on AVX512.
- Bitmask type for 32 elements, used for mask operations on AVX512.
- Bitmask type for 64 elements, used for mask operations on AVX512.
- A 128-bit SIMD vector with 4 elements of type
f32
. - A 256-bit SIMD vector with 8 elements of type
f32
. - A 512-bit SIMD vector with 16 elements of type
f32
. - A 128-bit SIMD vector with 2 elements of type
f64
. - A 256-bit SIMD vector with 4 elements of type
f64
. - A 512-bit SIMD vector with 8 elements of type
f64
. - A 128-bit SIMD vector with 16 elements of type
i8
. - A 256-bit SIMD vector with 32 elements of type
i8
. - A 512-bit SIMD vector with 64 elements of type
i8
. - A 128-bit SIMD vector with 8 elements of type
i16
. - A 256-bit SIMD vector with 16 elements of type
i16
. - A 512-bit SIMD vector with 32 elements of type
i16
. - A 128-bit SIMD vector with 4 elements of type
i32
. - A 256-bit SIMD vector with 8 elements of type
i32
. - A 512-bit SIMD vector with 16 elements of type
i32
. - A 128-bit SIMD vector with 2 elements of type
i64
. - A 256-bit SIMD vector with 4 elements of type
i64
. - A 512-bit SIMD vector with 8 elements of type
i64
. - Mask type with 8 bits. Its bit either all ones or all zeros.
- A 128-bit SIMD vector with 16 elements of type
m8
. - A 256-bit SIMD vector with 32 elements of type
m8
. - Mask type with 16 bits. Its bit either all ones or all zeros.
- Mask type with 32 bits. Its bit either all ones or all zeros.
- Mask type with 64 bits. Its bit either all ones or all zeros.
- A 128-bit SIMD vector with 8 elements of type
m16
. - A 256-bit SIMD vector with 16 elements of type
m16
. - A 128-bit SIMD vector with 4 elements of type
m32
. - A 256-bit SIMD vector with 8 elements of type
m32
. - A 128-bit SIMD vector with 2 elements of type
m64
. - A 256-bit SIMD vector with 4 elements of type
m64
. - A 128-bit SIMD vector with 16 elements of type
u8
. - A 256-bit SIMD vector with 32 elements of type
u8
. - A 512-bit SIMD vector with 64 elements of type
u8
. - A 128-bit SIMD vector with 8 elements of type
u16
. - A 256-bit SIMD vector with 16 elements of type
u16
. - A 512-bit SIMD vector with 32 elements of type
u16
. - A 128-bit SIMD vector with 4 elements of type
u32
. - A 256-bit SIMD vector with 8 elements of type
u32
. - A 512-bit SIMD vector with 16 elements of type
u32
. - A 128-bit SIMD vector with 2 elements of type
u64
. - A 256-bit SIMD vector with 4 elements of type
u64
. - A 512-bit SIMD vector with 8 elements of type
u64
.
Traits§
Functions§
- Splits a slice into chunks of equal size (known at compile time).
- Splits a slice into chunks of equal size (known at compile time).
- Safe transmute function.
- Safe lossy transmute function, where the destination type may be smaller than the source type.
Type Aliases§
Attribute Macros§
- with_
simd macro
Requires the first non-lifetime generic parameter, as well as the function’s first input parameter to be the SIMD type. Also currently requires that all the lifetimes be explicitly specified.